package com.zxj.geekstudy.other.proxy.dynamic;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * 验证java动态代理可直接代理接口，不需要有实现类
 */
public class ProxyHandler2 implements InvocationHandler {
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("Before invoke "  + method.getName());
        System.out.println("After invoke " + method.getName());
        return null;
    }

    public static void main(String[] args) {
        System.getProperties().setProperty("sun.misc.ProxyGenerator.saveGeneratedFiles", "true");

        Class<Hello2Interface> clazz = Hello2Interface.class;
        Hello2Interface proxyHello = (Hello2Interface) Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz}, new ProxyHandler2());

        proxyHello.hello();
    }
}
